<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简单计算器</title>
    <style>
        /* 简单的样式设置 */
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f4f4f9;
        }

        .calculator {
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        #display {
            width: 100%;
            height: 50px;
            font-size: 24px;
            text-align: right;
            margin-bottom: 10px;
        }

        .buttons {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 10px;
        }

        button {
            padding: 10px;
            font-size: 18px;
            border: none;
            background-color: #e0e0e0;
            cursor: pointer;
            border-radius: 5px;
        }

        button:hover {
            background-color: #d0d0d0;
        }
    </style>
    <!-- 引入 Vue 3.0 库 -->
    <script src="../libs/vue.global.min.js"></script>
</head>

<body>
    <div id="app" class="calculator">
        <!-- 显示输入和结果的输入框 -->
        <input type="text" :value="displayValue" readonly>
        <div class="buttons">
            <!-- 数字按钮 -->
            <button @click="appendToDisplay('7')">7</button>
            <button @click="appendToDisplay('8')">8</button>
            <button @click="appendToDisplay('9')">9</button>
            <button @click="appendToDisplay('/')">/</button>
            <button @click="appendToDisplay('4')">4</button>
            <button @click="appendToDisplay('5')">5</button>
            <button @click="appendToDisplay('6')">6</button>
            <button @click="appendToDisplay('*')">*</button>
            <button @click="appendToDisplay('1')">1</button>
            <button @click="appendToDisplay('2')">2</button>
            <button @click="appendToDisplay('3')">3</button>
            <button @click="appendToDisplay('-')">-</button>
            <button @click="appendToDisplay('0')">0</button>
            <button @click="clearDisplay()">C</button>
            <button @click="calculateResult()">=</button>
            <button @click="appendToDisplay('+')">+</button>
        </div>
    </div>
    <script>
        const { createApp, ref } = Vue;

        const app = createApp({
            setup() {
                const displayValue = ref('');

                const appendToDisplay = (value) => {
                    displayValue.value += value;
                };

                const clearDisplay = () => {
                    displayValue.value = '';
                };

                const calculateResult = () => {
                    try {
                        displayValue.value = eval(displayValue.value);
                    } catch (error) {
                        displayValue.value = 'Error';
                    }
                };

                return {
                    displayValue,
                    appendToDisplay,
                    clearDisplay,
                    calculateResult
                };
            }
        });

        app.mount('#app');
    </script>
</body>

</html>